#ifndef 	_EZ_THREAD_H
#define 	_EZ_THREAD_H

#include "ezdef.h"
#include "ARMCM3.h"
#include "ezserver.h"

//scheduler.h
extern 	ez_thread_t *cur_task;	
extern 	list_t 			thread_suspend_list;

void 		tTaskSched(void);
void 		task_scheduler(void);
void 		ez_enter_critical(void);
void 		ez_exit_critical(void);
int 		scheduler_look_check(void);
void 		system_scheduler_init(void);
void 		system_scheduler_start(void);
void 		scheduler_insert_thread(ez_thread_t *task);
void 		scheduler_remove_thread(ez_thread_t *task);


//thead.h
ez_thread_t*	get_thread_self(void);
void 		task_init(ez_thread_t 	 *task, 
								void 			(	*entry)(void *), 
								void 		 		*param, 
								uint32_t 		*stack,
								uint8_t    	priority,
								uint32_t   	tick);
void 		task_startup(ez_thread_t *task);
void 		task_sleep(uint32_t tick);
void 		task_resume(ez_thread_t *thread);
void 		task_suspend(ez_thread_t *thread);
void 		task_yield(void);
void 		task_exit(void);

								
//irq.h
void 			tSetSysTickPeriod(uint32_t ms);
void 			ez_hw_interrupt_enable(uint32_t state);
uint32_t 	ez_hw_interrupt_disable(void);

								
//list.h
void list_init(list_t *list);
void list_insert_after(list_t *list,list_t *node);
void list_insert_before(list_t *list,list_t *node);
void list_remove(list_t *node);
uint8_t list_isempty(list_t *node);
uint32_t list_size(list_t *node);
list_t* list_remove_next(list_t *node);
								
//kserver.h
void bit_map_set(uint32_t *bitmap,uint32_t bit);
void bit_map_clear(uint32_t *bitmap,uint32_t bit);
uint32_t bit_map_find(uint32_t bitmap);

//idle.h
void idel_init(void);
void set_idle_callback(void (*callback)(void *));

//components.h
void system_init(void);

//clock.h
void tick_increase(void);
uint32_t tick_get(void);

//timer.h
void sys_timer_init(void);
void timer_init(ez_timer_t *timer,
								uint32_t timeout_tick,
								void (*timeout_fun)(void *param),
								void *param,
								uint32_t flag);
void timer_start(ez_timer_t *timer);
void timer_stop(ez_timer_t *timer);
void timer_check(void);
void thread_timeout(void *param);
void timer_contorl(ez_timer_t *timer,uint32_t flag,void *param);
								
//ipc.h
void ipc_object_init(ez_ipc_t *ipc);
void ipc_object_insert(ez_ipc_t *ipc,ez_thread_t *thread);
void ipc_resume(list_t *suspend_list);
void ipc_resume_all(list_t *suspend_list);
void ipc_object_wait(ez_ipc_t *ipc,ez_thread_t *thread,uint32_t time);
uint8_t ipc_isempty(ez_ipc_t *ipc);
uint32_t sem_get_value(ez_ipc_sem_t * sem);

//sem.h
void sem_object_init(ez_ipc_sem_t * sem,uint32_t value);
uint32_t sem_task(ez_ipc_sem_t * sem,uint32_t time);
uint32_t sem_release(ez_ipc_sem_t * sem);
                
//memPort.h
void memPort_Init(ez_memport_t *memPort, uint8_t	*memStart, uint32_t  memCnt, uint32_t  memSize);
void memPort_getMem(ez_memport_t *memPort, uint8_t **mem);
uint32_t memPort_Take(ez_memport_t *memPort, uint8_t **mem, uint32_t time);
void memPort_Release(ez_memport_t *memPort, uint8_t *mem);



#endif
